<template>
  <a-input @blur="blur" v-model="num" addon-after="%" @change="change(num)" v-bind="$attrs" />
</template>
<script>
export default {
  name: 'mInput',
  components: {},
  props: ['value'],
  data() {
    return {
      num: ''
    }
  },
  mounted() {
    this.num = this.value

  },
  watch: {
    value(v) {
      this.num = v
    }
  },
  methods: {
    blur(v){
      this.$emit('blur',this.num)
    },
    change(v) {
      v = v.replace(/^\D*(\d*(?:\.\d{0,2})?).*$/g, '$1')
      // console.log(v)
      this.num = v
      this.$emit('input', v)
      this.$emit('change.value', v);
      this.$emit('change', v);
      this.$emit('input', v);
    }
  }
}
</script>
<style lang="css" scoped></style>
